# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo.exceptions import ValidationError

class Empjobhist(models.Model):

    _name = 'emp.jobhist'
    peo_id = fields.Many2one(comodel_name='emp.peo')


    pautono = fields.Many2one(string='人員自動編號', comodel_name='emp.peo')
    autono = fields.Char('電腦自動編號')
    cname = fields.Char('姓名(中文)')
    shname = fields.Char('服務機關學校名稱') # 自動帶入學校名稱
    jobname = fields.Char(string='職務名稱')
    joblev = fields.Char(string='官等職等')
    sallev = fields.Char('俸級')
    salpt = fields.Char('俸點')  # 在empcodedet找不到
    depname = fields.Char(string='部門名稱')  ####
    jobinday = fields.Datetime('起始日期')
    joboutday = fields.Datetime('結束日期')
    servtol = fields.Char('總服務年資(月合計)')
    outreason = fields.Char(string='離職原因')  # 57
    shmaster = fields.Char('首長姓名')
    edname = fields.Char('證明文件名稱')
    ednum = fields.Char('聘書字號')
    isbus = fields.Many2one(string='是否為業者（是否計入表1-2-1)',comodel_name='emp.code')
    istea = fields.Many2one(string='是否為教學經歷',comodel_name='emp.code')
    ismysh = fields.Many2one(string='是否為本校經歷',comodel_name='emp.code')
    depkind = fields.Many2one(string='部別',comodel_name='emp.codedepkind')
    deptype = fields.Char('學制')
    depno = fields.Many2one(string='行政一級單位/單位(科系)', comodel_name='emp.codedep')
    jobno = fields.Many2one(string='職稱(校內)',comodel_name='emp.code')
    admin = fields.Many2one(string='主管別',comodel_name='emp.code')
    jobnum = fields.Char('')
    fulltime = fields.Many2one(string='專兼任', comodel_name='emp.code')
    servyear = fields.Integer('服務年資-年')
    servmonth = fields.Integer('服務年資-月')
    jobno_sh = fields.Many2one(string='職稱(薪資)',comodel_name='emp.codejob')
    teapro = fields.Many2one(string='教師專業別',comodel_name='emp.code')
    depno_sub = fields.Many2one(string='行政二級單位', comodel_name='emp.codedep')
    update_user = fields.Char('維護人員')
    update_date = fields.Char('維護日期')
    iscaljob = fields.Boolean('是否計入退休年資')
    depgroup = fields.Char(string='學院/所屬學群')
    inpeo = fields.Boolean('主聘')
    adminunit = fields.Char(string='主要單位')
    jobkind = fields.Many2one(string='職務別',comodel_name = 'emp.code')
    memo = fields.Char('備註')
    printseris = fields.Char('列印順序')
    ischeck = fields.Boolean('是否審核通過')
    shyear = fields.Integer('學年度')
    isadapt = fields.Boolean('是否採計')
    kind = fields.Char()  # 無法判斷
    kindnum = fields.Char()
    gen_dep = fields.Many2one(string="部門名稱3",comodel_name='emp.codedep')
    applyname = fields.Char()
    datawkey = fields.Char()
    fpjobkind = fields.Char(string='校外經歷專兼職業別')
    sh_session = fields.Selection(string="學期",selection=[('1', '1'), ('2', '2')])
    checker = fields.Char()
    depcheck = fields.Char()
    isnow = fields.Boolean()
    hist_type = fields.Char()
    cooperation_type = fields.Char()

    @api.onchange('pautono')
    def set_peo_job(self):
        peo_data = self.env['emp.peo'].search([('id', '=', self.pautono.id)])
        self.cname = peo_data.cname
